# coding: utf-8
from typing import Any

from qtpy.QtCore import QPropertyAnimation, Property, QEasingCurve
from qtpy.QtWidgets import QGraphicsDropShadowEffect


class AnimationShadowEffect(QGraphicsDropShadowEffect):

    def __init__(self, parent=None):
        super().__init__(parent)
        self._radius = 0
        self.__animation = QPropertyAnimation(self)
        self.__animation.setTargetObject(self)
        self.__animation.setPropertyName(b'radius')

    def setDuration(self, msecs: int):
        self.__animation.setDuration(msecs)

    def setKeyValue(self, key, value: Any):
        self.__animation.setKeyValueAt(key, value)

    def setStartValue(self, value: Any):
        self.__animation.setStartValue(value)

    def setEndValue(self, value):
        self.__animation.setEndValue(value)

    def setEasingCurve(self, easing_curve: QEasingCurve.Type):
        self.__animation.setEasingCurve(easing_curve)

    def setLoopCount(self, loop_count):
        self.__animation.setLoopCount(loop_count)

    def start(self):
        self.__animation.start()

    def stop(self, r: int = 0):
        # 停止动画并修改半径值
        self.__animation.stop()
        self.radius = r

    @Property(int)
    def radius(self):
        return self._radius

    @radius.setter
    def radius(self, r):
        self._radius = r
        self.setBlurRadius(r)

    def s(self):
        self.__animation.s